<?php
declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Logic\Config as ConfigLogic;

class ConfigController extends Controller
{
    private $configLogic = null;

    public function __construct(){
        $this->configLogic = new ConfigLogic();
    }

    public function edit(Request $request){
        if ($request->isMethod('POST')) {
            $result = ['status'=>false, 'msg'=>'修改失败！'];

            $data['system_name']= $request->input('system_name','');
            $data['system_url']= $request->input('system_url','');
            $data['system_logo']= $request->input('system_logo','');
            $data['system_icp']= $request->input('system_icp','');
            $data['system_copy']= $request->input('system_copy','');
            $data['seo_title']= $request->input('seo_title','');
            $data['seo_keyword']= $request->input('seo_keyword','');
            $data['seo_description']= $request->input('seo_description','');
            $data['contact_wechat']= $request->input('contact_wechat','');
            $data['contact_phone']= $request->input('contact_phone','');

            if ($this->configLogic->update($data)){
                $result['status'] = true;
                $result['msg'] = '设置成功！';
                return response()->json($result);
            }

            return response()->json($result);
        } else {
            $data = $this->configLogic->select();
            if (empty($data)) abort(403, '获取数据失败！');
            return view('config.edit', ['data' => $data]);
        }
    }
}
